var pr_handles = [];

var _cti = window.parent;

/*
var proxy = {
	function setBusy(isBusy, busyType) {
    phone.m7SetBusy(isBusy, busyType);
	}
	
	function answerCall() {
	}
	
	function makeCall(phoneNum, type) {
    phone.dialout(phoneNum, type);
	}
	
	function hangup() {
    phone.hangup();
	}
	
	function hold() {
    phone.hold();
	}
	
	function 
	
	function stopConsult() {
    phone.stopConsult();
	}
	
};
*/
function pr_subscribe() {
	_cti.m7Phone = phone;

    var evtHandle;
    evtHandle = phone.register("EvtPeerToolBarChange", this, pr_EvtPeerToolBarChange);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtCallToolBarChange", this, pr_EvtCallToolBarChange);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtBarChange", this, pr_EvtBarChange);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtMonitorQueue" , this, pr_EvtMonitorQueue);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtHangup", this, pr_EvtHangup);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtRing", this, pr_EvtRing);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtPeerStatusChanged", this, pr_EvtPeerStatusChanged);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtConnected", this, pr_EvtConnected);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtCallStatusChanged", this, pr_EvtCallStatusChanged);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtLogon", this, pr_EvtLogon);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtDialing", this, pr_EvtDialing);
    pr_handles.push(evtHandle);
    evtHandle = phone.register("EvtCall", this, pr_EvtCall);
    pr_handles.push(evtHandle);
}

function pr_unsubscribe() {
    pr_handles.forEach((item, index, array)=>{
    	//moor.unsubscribe(item);
    	phone.m7Noregister(item);
    });
    pr_handles = [];
}

function pr_process(type, data) {
    _cti.onsdkevent(type, data);
}

function pr_EvtPeerToolBarChange(data) {
    _cti.onsdkevent("EvtPeerToolBarChange", data);
}

function pr_EvtCallToolBarChange(data) {
    _cti.onsdkevent("EvtCallToolBarChange", data);
}

function pr_EvtBarChange(data) {
    _cti.onsdkevent("EvtBarChange", data);
}

function pr_EvtMonitorQueue(data) {
    var data1;
    if (typeof(data)==="object") {
        data1 = {};
        Object.keys(data).forEach((key) => {
            if (key == "members") {

            } else {
                data1[key] = data[key];
            }
        })
    } else {
        data1 = data;
    }
    //_cti.onsdkevent("EvtMonitorQueue", data1);
}

function pr_EvtHangup(data) {
    _cti.onsdkevent("EvtHangup", data);
}

function pr_EvtRing(data) {
    _cti.onsdkevent("EvtRing", data);
}

function pr_EvtPeerStatusChanged(data) {
    _cti.onsdkevent("EvtPeerStatusChanged", data);
}

function pr_EvtConnected(data) {
    _cti.onsdkevent("EvtConnected", data);
}

function pr_EvtCallStatusChanged(data) {
    _cti.onsdkevent("EvtCallStatusChanged", data);
}

function pr_EvtLogon(data) {
    _cti.onsdkevent("EvtLogon", data);
}

function pr_EvtDialing(data) {
    _cti.onsdkevent("EvtDialing", data);
}

function pr_EvtCall(data) {
    _cti.onsdkevent("EvtCall", data);
}
